<template>
  <el-dialog
      v-model="dialogShow"
      :close-on-click-modal="false"
      title="代理签约结果"
      width="400px"
      @closed="close"
  >

    <div style="display: flex;justify-content: space-around">
      <el-radio v-model="radio" label="1" size="large">已签约</el-radio>
      <el-radio v-model="radio" label="2" size="large">开发失败</el-radio>
    </div>

    <template #footer>
      <div class="dialog-footer">
        <el-button
            class="border-btn"
            size="small"
            @click="close"
        >取消
        </el-button>
        <el-button
            class="main-btn"
            size="small"
            type="primary"
            @click="confirm"
        >确定
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import {defineComponent, getCurrentInstance, inject, reactive, toRefs} from 'vue'

export default defineComponent({
  name: 'ResultDialog',
  emits:['success'],
  setup(props, {emit}) {
    const currentInstance = getCurrentInstance()
    const api = inject('api')
    var data = reactive({
      dialogShow: false,
      radio: '1',
      id: 0
    })

    const open = (id) => {
      data.id = id
      data.dialogShow = true
    }

    const close = () => {
      data.dialogShow = false
    }

    const confirm = () => {
      const d = {
        planDetailId: data.id,
        result: data.radio
      }
      api.plan.PLAN_AGENT_CONTRACT_RESULT(d).then(res => {
        if (!res.code) {
          emit('success')
          currentInstance.proxy.customMessage({type: 'success', message: '更新成功'})
          close()
        } else {
          currentInstance.proxy.customMessage({type: 'error', message: res.msg})
        }
      })
    }

    return {
      ...toRefs(data),

      close,
      open,
      confirm,
    }
  }
})
</script>

<style scoped>

</style>
